package com.collabscm.md.base.web;


import org.apache.struts2.convention.annotation.Result;
import org.apache.struts2.convention.annotation.Results;

import com.collabscm.md.base.model.Organ;
import com.collabscm.md.base.service.OrganService;
import com.collabscm.pf.util.JsonUtils;
import com.collabscm.pf.web.BaseAction;

@Results(
//Struts的 Result配置
{
	@Result(name=OrganAction.ORGAN_LIST, location="/organ/organList.jsp"),//组织列表
	@Result(name=OrganAction.QUERY_ORGAN_REQ, location="/organ/queryOrgan.jsp"),//组织请求页面
	@Result(name=OrganAction.ADD_ORGAN_REQ, location="/organ/addOrgan.jsp"),//组织请求页面
	@Result(name=OrganAction.OPERATE_ORGAN_RESULT, location="/organ/operateOrganResult.jsp")//操作组织后的页面
}
)
public class OrganAction extends BaseAction {
	
	/**
	 * 返回组织列表
	 */
	private static final String ORGAN_LIST = "organList"; 
	
	/**
	 * 返回组织请求页面
	 */
	private static final String QUERY_ORGAN_REQ = "queryOrganReq"; 
	
	/**
	 * 返回添加组织请求页面
	 */
	private static final String ADD_ORGAN_REQ = "addOrganReq"; 
	
	/**
	 * 返回操作组织后的页面
	 */
	private static final String OPERATE_ORGAN_RESULT = "operateOrganResult"; 
	
	private static final long serialVersionUID = 1L;
	
	/**
	 * 组织对象
	 */
	private Organ organ;
	
	private OrganService getOrganService() {
		return getService(OrganService.class);
	}

	/**
	 * 分页查询组织列表
	 */
	@SuppressWarnings("unchecked")
	public String queryOrgan() throws Exception {
		//logDebug("：：：：：：：：：：：：：：：： {} ", organ.getOrganCnName());
		logDebug("::::" + page.getStartIndex());
		//logDebug("::::" + page.getPageSize());
		page = getOrganService().getAllOrgan(organ, page);
		this.getRequest().setAttribute("test", "test");
		logDebug("Find organ 总数为 : {} ", page.getTotalSize());
		return ORGAN_LIST;
	}
	
	/**
	 * 组织查询请求
	 * @return
	 * @throws Exception
	 */
	public String queryOrganReq() throws Exception {
		return QUERY_ORGAN_REQ;
	}
	
	/**
	 * 添加组织请求页面
	 * @return
	 * @throws Exception
	 */
	public String addOrganReq() throws Exception {
		return ADD_ORGAN_REQ;
	}

	/**
	 * 添加组织
	 * @return
	 * @throws Exception
	 */
	public void addOrgan() throws Exception {
		getOrganService().addOrgan(organ);
		//return OPERATE_ORGAN_RESULT;
		//JsonUtils.toJsonObjectString("{success}");
	}
	
	public Organ getOrgan() {
		return organ;
	}

	public void setOrgan(Organ organ) {
		this.organ = organ;
	}
	
}
